package com.goushu.controller;

import com.goushu.pojo.Book;
import com.goushu.pojo.Comment;
import com.goushu.pojo.PageBean;
import com.goushu.pojo.Result;
import com.goushu.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
@Slf4j
public class BookController {

    @Autowired
    private BookService bookService;

    /**
     *获取主页图书
     * @return
     */
    @GetMapping
    public Result<List<Book>> listMain() {
        List<Book> lb = bookService.listMain();
        return Result.success(lb);
    }

    /**
     *
     * 获取图书详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Result<Book> listDetail(Integer id) {
        Book b = bookService.listDetail(id);
        return Result.success(b);
    }

    /**
     * 获取图书评论
     * @param id
     * @return
     */
    @GetMapping("/comment")
    public Result<List<Comment>> listComment(Integer id) {
        List<Comment> c = bookService.listComment(id);
        return Result.success(c);
    }

    /**
     * 获取图书搜索结果
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/search")
    public Result<PageBean<Book>> search(Integer pageNum, Integer pageSize, String keyword) {
        PageBean<Book> pb = bookService.search(pageNum, pageSize, keyword);
        return Result.success(pb);
    }

    /**
     * 获取图书分类结果
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/category")
    public Result<PageBean<Book>> category(Integer pageNum, Integer pageSize, String keyword) {
        PageBean<Book> pb = bookService.category(pageNum, pageSize, keyword);
        return Result.success(pb);
    }

}
